package com.fuego.creditsystemuser.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.dto.Result;
import org.example.dto.UserDTO;
import org.example.entity.UserInfo;
import com.fuego.creditsystemuser.mapper.UserInfoMapper;
import com.fuego.creditsystemuser.service.IUserInfoService;
import org.example.utils.UserHolder;
import org.springframework.stereotype.Service;


@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService {
    @Override
    public UserInfo getById(Long userId) {
        return lambdaQuery().eq(UserInfo::getUserId, userId).one();
    }

    @Override
    public Result saveUserInfo(UserInfo userInfo){
        UserDTO user= UserHolder.getUser();
        userInfo.setUserId(user.getId());

        boolean isSuccess=save(userInfo);
        if(!isSuccess){
            return Result.fail("实名认证失败");
        }

        return Result.ok(userInfo.getUserId());
    }
}
